import Cookies from 'js-cookie'

const TokenKey = 'Dihong-Token'

const useSession = true

export function getToken() {
  return useSession ? sessionStorage.getItem(TokenKey) : Cookies.get(TokenKey)
}

export function setToken(token) {
  return useSession ? sessionStorage.setItem(TokenKey, token) : Cookies.set(TokenKey, token)
}

export function removeToken() {
  return useSession ? sessionStorage.removeItem(TokenKey) : Cookies.remove(TokenKey)
}

export function getCache(key) {
  return useSession ? sessionStorage.getItem(key) : Cookies.get(key)
}

export function setCache(key, token) {
  return useSession ? sessionStorage.setItem(key, token) : Cookies.set(key, token)
}

export function removeCache(key) {
  return useSession ? sessionStorage.removeItem(key) : Cookies.remove(key)
}
